package itsm.isperp.module.service.app;

import itsm.isperp.framework.service.BaseService;
import itsm.isperp.framework.utils.HibernateUUIDGenerator;
import itsm.isperp.module.entity.app.AppPortalRoleConfig;
import itsm.isperp.module.repository.app.AppPortalRoleConfigMapper;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

/**
 * @date 2014-2-24
 * @author Lizx
 */
@Service
public class AppPortalRoleConfigService extends
		BaseService<AppPortalRoleConfig> {

	@Resource
	protected AppPortalRoleConfigMapper appPortalRoleConfigMapper;

	@Override
	public AppPortalRoleConfigMapper getRepository() {
		return this.appPortalRoleConfigMapper;
	}

	public void saveRoleConfig(String roleId, String[] portalIds,
			String[] orderNums) {

		this.getRepository().deleteByRoleId(roleId);

		AppPortalRoleConfig[] arr = new AppPortalRoleConfig[portalIds.length];
		for (int i = 0; i < arr.length; i++) {
			AppPortalRoleConfig item = new AppPortalRoleConfig();
			item.setId(HibernateUUIDGenerator.generate());
			item.setAppPortalId(portalIds[i]);
			item.setAppRoleId(roleId);
			item.setOrderNum(Integer.valueOf(orderNums[i]));
			arr[i] = item;
		}

		this.getRepository().saveBatch(roleId, arr);

	}

}
